<template>
  <div id="app">
    <m-head v-if="fun.isWindVane()">
      <!-- app 沉浸式状态栏适配 -->
    </m-head>
    <div
      id="appMain"
      :class="[fun.getPhoneEnv() == 3 && !fun.isApp() && (!$route.meta.isPC || ($store.state.caseLibrary != null && $store.state.caseLibrary.set.pc_style == 0)) ? 'pcStyle' : '']"
      :style="{
        width: fun.getPhoneEnv() == 3 && !fun.isApp() && (!$route.meta.isPC || ($store.state.caseLibrary != null && $store.state.caseLibrary.set.pc_style == 0)) ? '375px' : '',
        margin: fun.getPhoneEnv() == 3 && !fun.isApp() && (!$route.meta.isPC || ($store.state.caseLibrary != null && $store.state.caseLibrary.set.pc_style == 0)) ? '0 auto' : ''
      }"
    >
      <keep-alive>
        <router-view v-if="!$route.meta.notKeepAlive && isRouterAlive && !$route.meta.notKeepAliveKey" :key="$route.fullPath" @changeFoot="initFoot"></router-view>
        <router-view v-if="!$route.meta.notKeepAlive && isRouterAlive && $route.meta.notKeepAliveKey" @changeFoot="initFoot"></router-view>
      </keep-alive>
      <router-view v-if="$route.meta.notKeepAlive && isRouterAlive" :key="$route.fullPath"></router-view>
      <loading></loading>
    </div>

    <!-- 返回直播按钮 -->
    <div id="returnLiveBtn" v-if="isShowReturnLiveBtn" @click.stop="gotoLiveRoom">
      <i class="fa fa-angle-left"></i><span class="rlbtext">返回直播<i class="iconfont icon-adsystem_icon_cancle clone_btn_style" @click.stop="clearLiveBtn"></i></span>
    </div>
    <!-- 返回直播按钮end -->

    <!--旧装修的底部导航-->
    <!--<c-foot v-if="!foot && $store.state.temp.item.menustyle && !$store.state.temp.item.menus.page_info"></c-foot>-->
    <!--旧装修的底部导航end-->

    <!--新装修的底部导航-->
    <U_foot
      v-if="!foot && ($store.state.temp.item.is_decorate === 1 || $store.state.temp.item.menus === '' || ($store.state.temp.item.menus && $store.state.temp.item.menus.page_info))"
      :id="id + '1'"
    ></U_foot>
    <!--新装修的底部导航end-->
    <qrCode v-if="fun.getPhoneEnv() == 3 && !fun.isApp() && (!$route.meta.isPC || ($store.state.caseLibrary != null && $store.state.caseLibrary.set.pc_style == 0)) && !fun.isWXWork()"></qrCode>
    <crmBind v-if="isShowCrmBind">
      <!-- 益生 crm账号绑定 -->
    </crmBind>
    <walletBind v-if="isShowWalletBind && this.fun.isWalletApp() && !isCloneWalletBind"><!-- 钱包地址绑定【#4203】 --></walletBind>
    <yz-wechat-share-img v-model="showWechatshar" :text="shareText"><!-- 全屏提示框，提示浏览器打开 --></yz-wechat-share-img>
  </div>
</template>

<script>
// import cFoot from "components/foot";
import U_foot from "components/new_diy/foot";
import loading from "components/loading";
import qrCode from "components/qrCode";
import crmBind from "components/other/crmBind";
import walletBind from "components/other/walletBind";
import yzWechatShareImg from "components/ui_components/yz_wechatShareImg";
import mHead from "components/other/mHead";

// import { mapState, mapMutations } from 'vuex';
//import BMap from 'BMap';

let isCreated = 0;
export default {
  data() {
    return {
      invite: "",
      //记录form请求微信form请求只发送一次
      selected: false,
      foot: true,
      zone: "",
      isLocation: false,
      isRouterAlive: true,

      is_Inviter: "",
      invite_mobile: "",
      isCloneWalletBind: false,//是否自己关闭了钱包弹出

      id: "M" + new Date().getTime(),
    };
  },
  provide() {
    return {
      reload: this.reload
    };
  },
  computed: {
    isShowReturnLiveBtn() {
      return this.$store.state._isShowReturnLiveBtn;
    },
    isShowCrmBind() {
      return this.$store.state._isShowCrmBind;
    },
    isShowWalletBind() {
      return this.$store.state._isShowWalletBind;
    },
    showWechatshar(){
      return this.$store.state.showWechatshar.value;
    },
    shareText(){
      return this.$store.state.showWechatshar.text;
    }
  },
  watch: {
    //监测路由变化
    $route(to, from) {
      if (from.path === "/") {
        if (this.fun.getKey("t")) {
          this.reload();
        }
      }
      if (to.meta.title) {
        this.fun.setWXTitle(to.meta.title);
      } else {
        let shopName = this.$store.state?.temp?.mailInfo?.name || null;
        if (shopName) this.fun.setWXTitle(shopName);
      }
      this.foot = to.meta.foot;

      // 浏览足迹  页面切换时更新new_page_comeIn
      window.new_page_comeIn = 1;
    }
  },

  mounted() {
    let titleName = '加载中';
    try {
      if(this.fun.isCPS()) {
        titleName = cps.getAppName();
      }
      if(this.fun.isXueXiApp()) {
        titleName = null;
      }
    } catch (error) {
      console.log('获取app标题======',error);
    }
    if(titleName) this.fun.setWXTitle(titleName);
    this.isCloneWalletBind = localStorage.getItem("isCloneWalletBind")||false;
    window.homeFirst = 0;
    let that = this;

    /*区分关闭和刷新，关闭清理vid  start*/
    // 搬到index.html执行  因为要优先http.js执行
    // window.onload = function() {
    //   if (!window.sessionStorage["tempFlag"]) {
    //     window.localStorage.removeItem("uid");
    //     window.localStorage.removeItem("mid");
    //
    //     window.localStorage.removeItem("scope");
    //     window.localStorage.removeItem("appid");
    //     window.localStorage.removeItem("mob_parent");
    //     window.localStorage.removeItem("mob_user");
    //     window.localStorage.removeItem("timetamp");
    //     window.localStorage.removeItem("sign");
    //     window.localStorage.removeItem("videoReload");
    //     window.sessionStorage.removeItem("myLocation");
    //   } else {
    //     window.sessionStorage.removeItem("tempFlag");
    //   }
    // };
    window.onunload = function() {
      window.sessionStorage["tempFlag"] = true;
      window.localStorage.removeItem("vid");
      window.localStorage.removeItem("circle_invitation_id");
    };
    window.onbeforeunload = function() {
      window.sessionStorage["tempFlag"] = true;
      that.delCookie("memberlogin_status");
    };
    /*区分关闭和刷新，关闭清理vid end*/


    if(this.fun.getKey('reportId')){
      let feast_system_param = {
        reportId : this.fun.getKey('reportId'),// reportId 宴席id
        qyDomain : this.fun.getKey('qyDomain'),// qyDomain 宴席域名
        shopId : this.fun.getKey('shopId'),// shopId 商城id
        tenantId : this.fun.getKey('tenantId'),// tenantId 供应链id
        qyCode : this.fun.getKey('qyCode')// qyCode 宴席编码
      };
      window.localStorage.setItem("feast_system_param", JSON.stringify(feast_system_param));
    }
    if(this.fun.getKey('big_screen_owner_id')){
      let orderOtherParams = {
        big_screen_owner_id : this.fun.getKey('big_screen_owner_id'),// 大屏机主id
      };
      window.sessionStorage.setItem("isQRPay", true);
      window.sessionStorage.setItem("orderOtherParams", JSON.stringify(orderOtherParams));
    }
  },
  created() {
    if (isCreated === 0) {
      window.localStorage.removeItem("vid");
      // window.localStorage.removeItem("uid");
      window.localStorage.removeItem("mid");
      window.localStorage.removeItem("customizeHotelHead");
      this.initShare();
      this.getNowPackageDeliver(); //更新自提点关联
    }
    if(this.fun.getKey('shrID')) window.sessionStorage.setItem('shrID',this.fun.getKey('shrID')||0);
    if(this.fun.getKey('min_token')){
      window.sessionStorage.setItem("min_token", this.fun.getKey('min_token'));
    }

    let supplier_alone_id = this.fun.getKey('supplier_alone_id') || sessionStorage.getItem("supplier_alone_id") || null; //供应商独立模板，获取供应商id
    if(supplier_alone_id){
      // 供应商独立模板，记录供应商id
      if(this.fun.getKey('supplier_alone_id')) window.sessionStorage.setItem("supplier_alone_id", this.fun.getKey('supplier_alone_id'));

      // this.$i18n.locale = 'ru';//调试。手动设置为俄语

      let isLang = this.$i18n.locale !== 'en';
      console.log('当前的语言为：',this.$i18n.locale,'是否为国际版：',isLang);
      console.log('当前供应商id',supplier_alone_id);
      if(supplier_alone_id && isLang) {
        //开启了多语言，显示国际版模板，true为开启
        window.isInternational = true;
      }
    }

    if(this.fun.getKey('token') && this.fun.getKey('PayerID')) {
      this.applePayInit(); //applePay 148支付回调地址，获取参数更新订单状态
    }
  },
  beforeUpdate() {
    if (isCreated === 1) {
      this.initShare();
    }
  },

  updated() {
    isCreated = 1;
  },

  methods: {
    gotoLiveRoom() {
      this.$router.push(this.fun.getUrl("livePage"));
    },
    clearLiveBtn() {
      this.$store.commit("setReturnLiveBtn", false);
    },
    initFoot(item) {
      this.foot = item;
    },
    getCookie(name) {
      var arr,
        reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
      if ((arr = document.cookie.match(reg))) {
        return unescape(arr[2]);
      } else {
        return null;
      }
    },
    delCookie(name) {
      var exp = new Date();
      exp.setTime(exp.getTime() - 1);
      var cval = this.getCookie(name);
      if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    },
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(() => {
        this.isRouterAlive = true;
      });
    },

    //初始化分享设置
    initShare() {
      if (this.$route.meta.is_single_share) {
        // 加入设置了页面单独设置分享则不进行全局分享设置
        return;
      }
      let _url = document.location.href;
      this.fun.wxShare("", { url: _url }, { share_from: "app" });
    },

    wxLocationGet() {
      let json = {
        longitude: this.fun.getLat(),
        latitude: this.fun.getLng()
      };

      //获取城市信息
      $http
        .get("geocoding.get-address-component", json)
        .then(response => {
          console.log("TAG:", json);
          if (response.result == 1) {
            //通过获取的district获取zoneId
            //this.getZoneId(response.data.district);
            //window.localStorage.setItem("nowZone", response.data.district);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },

    getNowPackageDeliver() {
      let deliverIDStorage = sessionStorage.getItem("deliverId") || null; //获取当前会话是否存储了自提点id
      if (window.location.href.indexOf("deliverId") > -1 && !deliverIDStorage) {
        //添加判断sessionStorage是否已存在的目的是防止在其他页面刷新，关联的自提点又变成了链接上的，导致之前手动切换的失效
        let list = ["/home", "/newDiy", "/selfPickupPoint/category", "/selfPickupPoint/search"];
        for (let i = 0; i < list.length; i++) {
          if (window.location.href.indexOf(list[i]) > -1) {
            return false;
          }
        }
        let _dyID = this.fun.getKey("deliverId"); //获取链接上的参数，自提点id
        $http.get("plugin.package-deliver.frontend.decorate-deliver.getNowPackageDeliver", { deliver_id: _dyID }).then(
          response => {
            if (response.result === 1) {
              window.sessionStorage.setItem("deliverId", response.data.id); //储存到sessionStorage
            } else {
              this.$toast(response.msg);
            }
          },
          function(response) {
            console.log(response);
          }
        );
      }
    },
    async applePayInit() {
      let { result, msg } = await $http.get(this.pageOptions.showBindMemberOption.bindApi,{ token: this.fun.getKey('token') });
    }
  },
  components: { U_foot, loading, qrCode, crmBind, walletBind, yzWechatShareImg, mHead }
};
</script>
<style lang="scss" rel="stylesheet/scss">
@import "assets/css/font-awesome.min.css";
@import "assets/css/app.scss";
@import "layout";

// @media only screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) {
//   #app {
//     box-sizing: border-box;
//     padding-bottom: 34px;
//     &:after {
//       content: "";
//       z-index: 9998;
//       position: fixed;
//       left: 0;
//       bottom: 0;
//       width: 100%;
//       height: 34px;
//       background: #fff;
//     }
//   }
// }
// ----- #appMain.pcStyle 用于pc端样式适配
#appMain.pcStyle {
  .mint-header {
    width: 375px;
    margin: 0 auto;
  }

  .mint-popup-4,
  .mint-navbar {
    width: 375px !important;
  }

  .mint-navbar {
    margin: 0 auto;
  }

  .yd-popup {
    width: 375px !important;
    right: 50%;
    margin-right: -187.5px;
  }

  // .van-popup {
  //   width: 375px !important;
  //   right: 50%;
  //   left: auto;
  //   margin-right: -187.5px;
  // }

  .yd-popup-show,
  .van-popup,
  .yd-navbar,
  .yd-actionsheet {
    width: 375px !important;
  }

  .van-popup--bottom {
    left: 50%;
    transform: translateX(-50%);
  }

  .yd-navbar,
  .yd-actionsheet {
    left: auto;
  }

  .set-pc-styleLeft {
    width: 375px !important;
    left: 50% !important;
    transform: translateX(-50%);
    // margin-left: -187.5px;
  }

  .set-pc-style {
    width: 375px !important;
    left: auto !important;
  }
}

.g-fix-ios-prevent-scroll {
  position: static;
}

.el-cascader-menus .el-cascader-menu {
  // 供应商选择分类
  min-width: 115px;

  .el-cascader-menu__item {
    width: 115px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.mint-indicator-wrapper {
  z-index: 2000;
}

#returnLiveBtn {
  position: fixed;
  bottom: 35%;
  display: flex;
  align-items: center;
  justify-content: center;
  left: 9;
  width: 4.5rem;
  height: 3rem;
  line-height: 3rem;
  background: #04be02;
  color: #fff;
  border-top-right-radius: 2rem;
  border-bottom-right-radius: 2rem;
  z-index: 999;

  i {
    font-size: 1rem;
  }

  .rlbtext {
    width: 2rem;
    line-height: 1rem;
    display: inline-block;
    margin: 0 0.5rem 0 0.25rem;
    font-size: 0.875rem;
    position: relative;

    .clone_btn_style {
      font-size: 1rem;
      padding: 0.5rem;
      color: #333;
      position: absolute;
      top: -1rem;
      right: -2.875rem;
    }
  }
}

#aggregate {
  .add_photo {
    overflow: hidden;

    input {
      height: 5rem !important;
      margin: 0;
    }
  }
}

// loading大小
img[lazy="loading"] {
  width: 40px !important;
  height: 40px !important;
  display: flex;
  justify-content: center;
  margin: 20% auto;
}

/* @ lijianping ----> 新增 */
.flex {
  display: flex;
}

.flex-column {
  display: flex;
  flex-direction: column;
}

.flex-a-c {
  display: flex;
  align-items: center;
}

.flex-a-s {
  display: flex;
  align-items: flex-start;
  align-items: stretch;
}

.flex-j-c {
  display: flex;
  justify-content: center;
}

.flex-j-se {
  display: flex;
  justify-content: space-evenly;
}

.flex-j-sa {
  display: flex;
  justify-content: space-around;
}

.flex-j-sb {
  display: flex;
  justify-content: space-between;
}
.f-grow-2 {
  flex: 2!important;
}
.f-grow-1 {
  flex: 1!important;
}

.size-con {
  background-repeat: no-repeat;
  background-size: contain;
}

.size-cov {
  background-repeat: no-repeat;
  background-size: cover;
}

.line-clamp-1 {
  overflow: hidden;
  text-overflow:ellipsis;
  white-space: nowrap;
}
.line-clamp-2 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.themeColor {
  color: var(--themeBaseColor);
}
.color-000000{
  color: #000000;
}
.margin-10{
  margin: 0 0.625rem!important;
}
.margin-top-2 {
  margin-top: 2px!important;
}
.margin-top-4 {
  margin-top: 0.25rem!important;
}
.margin-top-8 {
  margin-top: 0.5rem!important;
}
.margin-top-10{
  margin-top: 0.625rem!important;
}
.margin-bottom-8 {
  margin-bottom: 0.5rem!important;
}
.margin-left-4 {
  margin-left: 0.25rem!important;
}
.margin-left-6 {
  margin-left: 0.375rem!important;
}
.margin-right-6 {
  margin-right: 0.375rem!important;
}
.padding-10 {
  padding: 0.625rem!important;
}
.t-l{
  text-align: left;
}
.t-r{
  text-align: right;
}
.t-c{
  text-align: center;
}
.f-bold {
  font-weight: bold;
}
.f-10{
  font-size: 0.625rem;
}
.f-11{
  font-size: 0.6875rem;
}
.f-12{
  font-size: 0.75rem;
}
.f-13{
  font-size: 0.8125rem;
}
.f-14{
  font-size: 0.875rem;
}
.f-15{
  font-size: 0.9375rem;
}
.f-16{
  font-size: 1rem;
}
.f-18{
  font-size: 1.125rem;
}
.f-24{
  font-size: 1.5rem;
}
.f-20{
  font-size: 1.25rem;
}
.f-24{
  font-size: 1.5rem;
}
.f-28{
  font-size: 1.75rem;
}
.f-40{
  font-size: 2.5rem;
}

</style>
